package frist50;

import org.junit.jupiter.api.Test;

import java.util.*;

public class T0047 {
    Set<List<Integer>> set = new HashSet<>();
    List<Integer> tmp = new ArrayList<>();
    boolean[] b;
    public List<List<Integer>> permuteUnique(int[] nums) {
        b = new boolean[nums.length];
        permuteHelp(nums, nums.length);
        List<List<Integer>> lists = new ArrayList<>(set);
        return lists;
    }
    public void permuteHelp(int[] nums, int n) {
        if (n == 0) {
            set.add(new ArrayList<>(tmp));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (!b[i]) {
                tmp.add(nums[i]);
                b[i] = true;
                permuteHelp(nums, n - 1);
                tmp.remove(tmp.size() - 1);
                b[i] = false;
            }
        }
    }

    @Test
    public void test() {
        int[] ints = {1, 1, 2};
        System.out.println(permuteUnique(ints).toString());
    }
}
